#version 330 core
precision mediump float;

in vec2 tex_coord;
out vec4 frag_color;

uniform sampler2D y_texture;
uniform sampler2D uv_texture;
uniform int IMAGE_FORMAT;
uniform vec3 tex_color;

uniform mat3 yuv2rgb;

void main(void) {
  vec3 yuv;
  yuv.x = texture(y_texture, tex_coord).r;

  if (IMAGE_FORMAT == 5) { // NV21
	yuv.y = texture(uv_texture, tex_coord).g - 0.5; // GL_RG / GL_LUMINANCE_ALPHA
	yuv.z = texture(uv_texture, tex_coord).r - 0.5;
  } else if (IMAGE_FORMAT == 6) { // NV12
  	yuv.y = texture(uv_texture, tex_coord).r - 0.5;
	yuv.z = texture(uv_texture, tex_coord).g - 0.5;
  }

  frag_color = vec4(yuv2rgb * yuv, 1.0f) * vec4(tex_color, 1.0f);
}